package com.zznj.xzjc.fragment;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.view.RxToast;
import com.vondear.rxui.fragment.NewLazyFragment;
import com.zznj.xzjc.MainActivity;
import com.zznj.xzjc.R;
import com.zznj.xzjc.activity.index.push.ActivityPushMain;
import com.zznj.xzjc.activity.index.push.IndexPushActivity;
import com.zznj.xzjc.activity.person.PersonClearCacheActivity;
import com.zznj.xzjc.activity.person.PersonGuanYuWoMenActivity;
import com.zznj.xzjc.activity.person.PersonInfoActivity;
import com.zznj.xzjc.activity.person.PersonTuiSongSetActivity;
import com.zznj.xzjc.activity.person.PersonYiJianFanKuiActivity;
import com.zznj.xzjc.bean.index.PushData;
import com.zznj.xzjc.bean.index.PushResult;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.view.ImageViewPlus;
import com.zznj.xzjc.view.StatusBarUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import okhttp3.FormBody;

/**
 * 描述：线索发现
 */
public class PersonalCenterFragment extends NewLazyFragment {
    @BindView(R.id.person_username)
    TextView person_username;
    @BindView(R.id.person_danwei)
    TextView person_danwei;

    @BindView(R.id.person_grzl_linear)
    View person_grzl_linear;
    @BindView(R.id.person_tssz_linear)
    View person_tssz_linear;
    @BindView(R.id.gyss_yjfk_linear)
    View gyss_yjfk_linear;
    @BindView(R.id.gyss_gywm_linear)
    View gyss_gywm_linear;
    @BindView(R.id.gyss_set_linear)
    View gyss_set_linear;

    @BindView(R.id.titleLinear)
    LinearLayout titleLinear;
    Unbinder unbinder;

    @BindView(R.id.message_frame)
    View message_frame;
    @BindView(R.id.tishiTv)
    TextView tishiTv;

    @BindView(R.id.headPic)
    ImageViewPlus headPic;


    private LoginBean user;

    @Override
    protected int getContentViewId() {
        return R.layout.gyss_fragment_personalcenter_layout;
    }

    @Override
    protected void initView(View view) {
        unbinder = ButterKnife.bind(this, view);
    }


    @Override
    protected void initData() {
    }

    private void getData(){
        SubscriberOnNextListener<BaseBean<LoginBean>> onNextListener = baseBean -> {
            SharedHelper.saveKeyValueForString(mContext,"Member",new Gson().toJson(baseBean.getResult()));
            user = baseBean.getResult();
            titleLinear.setPadding(0,StatusBarUtil.getStatusBarHeight(mContext),0,0);
            person_username.setText(user.getUserName());
            person_danwei.setText("单位："+user.getOrgName());
        };
        HttpMethods.getInstance().getUser(new ProgressSubscriber<>(onNextListener, mContext, true));
    }

    @Override
    public void onResume() {
        super.onResume();
        user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        titleLinear.setPadding(0,StatusBarUtil.getStatusBarHeight(mContext),0,0);
        person_username.setText(user.getUserName());
        person_danwei.setText("单位："+user.getOrgName());
        getData();
    }

    @OnClick({R.id.person_grzl_linear, R.id.person_tssz_linear,R.id.gyss_yjfk_linear,R.id.gyss_gywm_linear,R.id.gyss_set_linear,R.id.message_frame})
    public void onViewClicked(View view) {
        if(view.getId() == R.id.person_grzl_linear){
            RxActivityTool.skipActivity(mContext, PersonInfoActivity.class);
        }else if(view.getId() == R.id.person_tssz_linear){
            RxActivityTool.skipActivity(mContext, PersonTuiSongSetActivity.class);
        }else if(view.getId() == R.id.gyss_yjfk_linear){
            RxActivityTool.skipActivity(mContext, PersonYiJianFanKuiActivity.class);
        }else if(view.getId() == R.id.gyss_gywm_linear){
            RxActivityTool.skipActivity(mContext, PersonGuanYuWoMenActivity.class);
        }else if(view.getId() == R.id.gyss_set_linear){
            RxActivityTool.skipActivity(mContext, PersonClearCacheActivity.class);
        }else if(view.getId() == R.id.message_frame){
            RxActivityTool.skipActivity(mContext, IndexPushActivity.class);
        }
    }
}
